package com.atguigu.tingshu.dispatch.job;

import com.atguigu.tingshu.search.client.SearchFeignClient;
import com.atguigu.tingshu.user.client.UserFeignClient;
import com.xxl.job.core.context.XxlJobHelper;
import com.xxl.job.core.handler.annotation.XxlJob;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class DispatchHandler {

    /**
     * 入门案例任务
     */
    @XxlJob("myJob")
    public void myJOb() {
        int shardIndex = XxlJobHelper.getShardIndex();
        int shardTotal = XxlJobHelper.getShardTotal();
        log.info("总分片数：{},当前执行器分片索引：{}", shardTotal, shardIndex);
    }


    @Autowired
    private UserFeignClient userFeignClient;

    /*
     * 每天凌晨0点更新会员标识
     * */
    @XxlJob("updateVipState")
    public void updateVipState() {
        log.info("每天凌晨0点更新会员标识");
        //远程调用用户服务更新会员过期用户VIP标识
        userFeignClient.updateVipExpireStatus();
    }


    @Autowired
    private SearchFeignClient searchFeignClient;

    /*
     * 每天每隔6小时更新排行榜数据
     * */
    @XxlJob("updateLatelyAlbumRanking")
    public void updateLatelyAlbumRanking() {
        log.info("更新排行榜数据");
        //远程调用搜索服务更新Redis排行榜数据
        searchFeignClient.updateLatelyAlbumRanking();
    }
}
